<?php


namespace app\admin\system\controller;


use app\admin\system\logic\DictDataLogic;
use app\common\controller\BaseAdminController;

class DictDataController extends BaseAdminController
{
    protected $noNeedRight = ['*'];

    protected $idKey = 'dictId';

    protected function init()
    {
        parent::init();
        $this->logic = new DictDataLogic();
    }

    protected function searchWhere()
    {
        $where = [];
        $this->form['dictName'] && $where[] = ['dictName', 'like', "%{$this->form['dictName']}%"];
        $this->form['dictType'] && $where[] = ['dictType', '=', $this->form['dictType']];
        $this->form['dictStatus'] && $where[] = ['dictStatus', '=', $this->form['dictStatus']];
        return $where;
    }

    public function listDataByType()
    {
        $dictType = input('dictType');

        $data = $this->logic->where('dictType', '=', $dictType)->select();
        return $this->success($data);
    }

    public function read()
    {
        $model = $this->logic->find(request()->input('id'));
        if ($model) {
            return $this->success($model->toArray());
        } else {
            return $this->error('未查找到信息');
        }
    }
}